//
//  HCalendarCollectionViewCell.swift
//  Drop
//
//  Created by hushaohua on 2018/6/30.
//  Copyright © 2018年 init. All rights reserved.
//

import UIKit

class HCalendarResultHeaderView : UICollectionReusableView{
    lazy var textLabel:UILabel = {
        var label:UILabel = UILabel(frame: self.bounds);
        label.text = "已选择";
        label.font = UIFont.systemFont(ofSize: 16, weight: .thin);
        label.textColor = UIColor.gray;
        label.autoresizingMask = [.flexibleWidth, .flexibleHeight];
        return label;
    }();
    
    override init(frame: CGRect) {
        super.init(frame: frame);
        self.addSubview(self.textLabel);
    }
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}

class HCalendarResultCell : UICollectionViewCell{
    lazy var textLabel:UILabel = {
        var label:UILabel = UILabel(frame: self.bounds);
        label.text = "1";
        label.font = UIFont.systemFont(ofSize: 18, weight: .thin);
        label.textColor = UIColor.darkGray;
        label.textAlignment = .center;
        label.autoresizingMask = [.flexibleWidth, .flexibleHeight];
        return label;
    }();
    
    override init(frame: CGRect) {
        super.init(frame: frame);
        self.contentView.addSubview(self.textLabel);
        self.contentView.backgroundColor = UIColor.white;
    }
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}

class HCalendarDayCell : UICollectionViewCell{
    override init(frame: CGRect) {
        super.init(frame: frame);
        self.contentView.addSubview(self.markView);
        self.contentView.addSubview(self.textLabel);
        self.contentView.backgroundColor = UIColor.white;
    }
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    var mark:Bool = false{
        didSet{
            self.markView.isHidden = !mark;
        }
    }
    
    lazy var markView:UIView = {
        let view:UIView = UIView(frame: self.bounds);
        view.backgroundColor = UIColor.h_lightblue().withAlphaComponent(0.5);
        view.isHidden = true;
        return view;
    }();
    
    lazy var textLabel:UILabel = {
        var label:UILabel = UILabel(frame: self.bounds);
        label.text = "1";
        label.font = UIFont.systemFont(ofSize: 20, weight: .medium);
        label.textAlignment = .center;
        label.autoresizingMask = [.flexibleWidth, .flexibleHeight];
        return label;
    }();
}

class HCalendarWeekCell : UICollectionViewCell{
    
    override init(frame: CGRect) {
        super.init(frame: frame);
        for _ in 0...6 {
            let view = self.markView();
            self.markViews.append(view);
            let label = self.dayLabel();
            self.labels.append(label);
        }
    }
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    lazy var labels:[UILabel] = {
        var labels = [UILabel]();
        return labels;
    }();
    
    lazy var markViews:[UIView] = {
        var views = [UIView]();
        return views;
    }();
    
    var mark:Bool = false{
        didSet{
            for view in self.markViews {
                view.isHidden = mark;
            }
        }
    }
    
    func markView() -> UIView{
        let view:UIView = UIView(frame: .zero);
        view.translatesAutoresizingMaskIntoConstraints = false;
        view.backgroundColor = UIColor.h_lightblue().withAlphaComponent(0.5);
        view.isHidden = true;
        return view;
    }

    func dayLabel() -> UILabel{
        let label:UILabel = UILabel(frame: .zero);
        label.translatesAutoresizingMaskIntoConstraints = false;
        label.text = "1";
        label.font = UIFont.systemFont(ofSize: 20, weight: .medium);
        label.textAlignment = .center;
        return label;
    }
    
    func addSubviewConstraints() {
        var views = [String : UIView]();
        var hLabelString = "H:|-";
        var hMarkString = "H:|-";
        for index in 0...6{
            views["label\(index)"] = self.labels[index];
            views["mark\(index)"] = self.markViews[index];
            
            hLabelString += "[label\(index)]-";
            hLabelString += (index == 6 ? "0-|" : "1-")
            
            hMarkString += "[mark\(index)]-";
            hMarkString += (index == 6 ? "0-|" : "1-")
        }
        var constraints = [NSLayoutConstraint]();
        
        constraints += NSLayoutConstraint.constraints(withVisualFormat: hLabelString, options: [.alignAllTop, .alignAllBottom], metrics: nil, views: views);
        constraints += NSLayoutConstraint.constraints(withVisualFormat: hMarkString, options: [.alignAllTop, .alignAllBottom], metrics: nil, views: views);
        constraints += NSLayoutConstraint.constraints(withVisualFormat: "V:|-0-[label0]-0-|", options: [.alignAllTop, .alignAllBottom], metrics: nil, views: views);
        constraints += NSLayoutConstraint.constraints(withVisualFormat: "V:|-0-[mark]-0-|", options: [.alignAllTop, .alignAllBottom], metrics: nil, views: views);
    }
}
